package com.cj.wisdom_display.http.cookie;

import com.cj.wisdom_display.MyApplication;

import java.util.List;

import okhttp3.Cookie;
import okhttp3.CookieJar;
import okhttp3.HttpUrl;

public class CookieManger implements CookieJar {


	public static String APP_PLATFORM = "app-platform";

	private static PersistentCookieStore cookieStore;

	public CookieManger() {
		if (cookieStore == null) {
			cookieStore = new PersistentCookieStore(MyApplication.instance);
		}

	}


	@Override
	public void saveFromResponse(HttpUrl url, List<Cookie> cookies) {
		if (cookies != null && cookies.size() > 0) {
			for (Cookie item : cookies) {
				cookieStore.add(url, item);
			}
		}
	}

	@Override
	public List<Cookie> loadForRequest(HttpUrl url) {
		List<Cookie> cookies = cookieStore.get(url);
		return cookies;
	}

	static class Customer {

		private String userID;
		private String token;

		public Customer(String userID, String token) {
			this.userID = userID;
			this.token = token;
		}

		public String getUserID() {
			return userID;
		}

		public void setUserID(String userID) {
			this.userID = userID;
		}

		public String getToken() {
			return token;
		}

		public void setToken(String token) {
			this.token = token;
		}

	}
}